package br.com.sisat.persistencia.conexao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import br.com.sisat.exception.ServiceException;

public  class ConnectionProvider  {

	public static Connection getDefaultConnection() throws Exception{
		Connection conn =null;
		String driver  = "org.postgresql.Driver";
		String urlConnection = "jdbc:postgresql://localhost:5432/sat";
		String user = "postgres";
		String password = "postgres";
		Class.forName(driver);
		conn =  DriverManager.getConnection(urlConnection , user , password);
		conn.setAutoCommit(false);
		return conn;
	}
	
	public static void fechaConexao(Connection conn) throws ServiceException{
		if(conn!=null){
			try {
				conn.rollback();
			} catch (SQLException e) {
				
			}finally{
				try{
					conn.close();
					
				} catch (SQLException e) {
					throw new ServiceException(e);
				}
			}
		}
	}
}
